package com.aiyige.model.enums;

import com.aiyige.MyApp;
import com.aiyige.R;

/**
 * Created by xiachao on 2017/12/25.
 */

public enum ErrorCode {
    ERROR_CODE_30001(30001, MyApp.getInstance().getString(R.string.error_code_30001)),
    ERROR_CODE_30002(30002, MyApp.getInstance().getString(R.string.error_code_30002)),;

    public int getCode() {
        return code;
    }

    public String getValue() {
        return value;
    }

    private int code;
    private String value;

    ErrorCode(int code, String value) {
        this.code = code;
        this.value = value;

    }

    /**
     * 根据key获取value
     *
     * @param key
     *            : 键值key
     * @return String
     */
    public static String getValueByKey(int key) {
        ErrorCode[] enums = ErrorCode.values();
        for (int i = 0; i < enums.length; i++) {
            if (enums[i].getCode() == key) {
                return enums[i].getValue();
            }
        }
        return "";
    }

    }
